package com.heking.securityapp.pages;

import android.os.Bundle;
import android.widget.Button;

import com.heking.security.LogUtils;
import com.heking.security.SharedPreferencesWrap;
import com.heking.securityapp.R;

import androidx.appcompat.app.AppCompatActivity;

public class SPActivity extends AppCompatActivity {
    private static final String TAG = ">>>SPActivity";
    private Button mBtn1;
    private Button mBtn2;
    private Button mBtn3;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_s_p);
        findViews();
        mBtn3.setOnClickListener(v->{
            SharedPreferencesWrap.clearAllSharedPrefs(this);
        });
        SharedPreferencesWrap.setDefaultKey("01234567891234560123456789123456");
        SharedPreferencesWrap.setDefaultIv("0123456789123456");
        SharedPreferencesWrap sp1 = SharedPreferencesWrap.with(this, "sp1");
        sp1.setEncryptEnable(true);
//        sp1.setIv("0123456789123456");
//        sp1.setKey("01234567891234560123456789123456");
        mBtn1.setOnClickListener(v -> {
            sp1.edit().putString("city", "重庆")
                    .putBoolean("enable",true)
                    .putDouble("price_double",119.2123)
                    .putFloat("price_float",12.21f)
                    .putInt("price_int",891)
                    .putLong("price_long",123123L)
                    .apply();
        });
        mBtn2.setOnClickListener(v -> {
            LogUtils.d(TAG, "city:"+sp1.getString("city",null));
            LogUtils.d(TAG, "enable:"+sp1.getBoolean("enable",false));
            LogUtils.d(TAG, "price_double:"+sp1.getDouble("price_double",0));
            LogUtils.d(TAG, "price_float:"+sp1.getFloat("price_float",0));
            LogUtils.d(TAG, "price_int:"+sp1.getInt("price_int",0));
            LogUtils.d(TAG, "price_long:"+sp1.getLong("price_long",0));

        });

    }

    private void findViews() {
        mBtn1 = findViewById(R.id.btn1);
        mBtn2 = findViewById(R.id.btn2);
        mBtn3 = findViewById(R.id.btn3);
    }
}